package fr.kotton.myorganizer.bean;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedList;

public class Task {

    private Integer id;
    private String title;                     // Title of the task
    private Date startDate;                   // Start date of the task (may be null)
    private Date endDate;                     // End date of the task (may be null)
    private FrequencyUnits frequencyUnit;     // Frequency of the task (may be null). See FrequencyUnits declaration.
    private Boolean notification = false;     // True if a notification is send when start date is reached.
    private Date reminderDelay;               // Delay before the start date to trigger the notification. Used Only if notification is true.
    private Boolean alarm = false;            // True if an alarm is triggered when the start date is reached.
    private TaskContentTypes taskContentType; // Type of the content of the task. See TaskContentTypes declaration.
    private LinkedList<TaskContent> taskContentEntries = new LinkedList<TaskContent>(); // Content of the task. Contains only one entry if the TaskContentType is textarea.
    private HashSet<Contact> contacts = new HashSet<Contact>();        // Contacts associated to the task
    private LinkedList<Integer> taskGroupsIds = new LinkedList<Integer>(); // Groups associated to the task

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    public String getFormattedEndDate() {
        DateFormat mDateFormatter = new SimpleDateFormat("EE dd MMM yyyy");
        return mDateFormatter.format(endDate);
    }

    public String getFormattedEndTime() {
        DateFormat mTimeFormatter = new SimpleDateFormat("HH:mm");
        return mTimeFormatter.format(endDate);
    }

    public FrequencyUnits getFrequencyUnit() {
        return frequencyUnit;
    }

    public void setFrequencyUnit(String frequencyUnit) {
        if (frequencyUnit != null) {
            this.frequencyUnit = FrequencyUnits.valueOf(frequencyUnit);
        }
    }

    public Boolean getNotification() {
        return notification;
    }

    public void setNotification(Boolean notification) {
        this.notification = notification;
    }

    public Date getReminderDelay() {
        return reminderDelay;
    }

    public void setReminderDelay(Date reminderDelay) {
        this.reminderDelay = reminderDelay;
    }

    public Boolean getAlarm() {
        return alarm;
    }

    public void setAlarm(Boolean alarm) {
        this.alarm = alarm;
    }

    public TaskContentTypes getTaskContentType() {
        return taskContentType;
    }

    public void setTaskContentType(String taskContentType) {
        if (taskContentType != null) {
            this.taskContentType = TaskContentTypes.valueOf(taskContentType);
        }
    }

    public LinkedList<TaskContent> getTaskContentEntries() {
        return taskContentEntries;
    }

    public void setTaskContentEntries(LinkedList<TaskContent> taskContentEntries) {
        this.taskContentEntries = taskContentEntries;
    }

    public HashSet<Contact> getContacts() {
        return contacts;
    }

    public void setContacts(HashSet<Contact> contacts) {
        this.contacts = contacts;
    }

    public LinkedList<Integer> getTaskGroupsIds() {
        return taskGroupsIds;
    }

    public void addTaskGroupsId(Integer groupId) {
        this.taskGroupsIds.add(groupId);
    }
}
